<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>后台管理</title>
{{include file="layouts/_head"}}
</head>
<body>
<div class="main">
    <ol class="breadcrumb">
        <li><i class="icon_home iconfont"></i>首页</li>
        <li>产品管理</li>
        <li class="active">产品模型</li>
    </ol>
    <div class="bg-1 clearfix main-head-info">
        <a type="submit" class="btn btn-success btn-sm" href="{{:url('/admin/product_model/create')}}">创建模型</a>
        <button type="submit" class="btn btn-danger btn-sm" onclick="delAction()">批量删除</button>
        <span class="pull-right margin-t-5">共有数据：<strong>{{$product_models->total()}}</strong> 条</span>
    </div>
    <div class="main-con">
        {{if $product_models->total() > 0}}
        <table class="table table-bordered table-hover">
            <thead>
                <tr>
                    <th><input type="checkbox" name="" value=""></th>
                    <th>模型名</th>
                    <th>描述</th>
                    <th>状态</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
                {{volist name="product_models" id="vo" key="key" }}
                <tr id="{{$vo.id}}">
                    <td><input type="checkbox" /></td>
                    <td>{{$vo.name}}</td>
                    <td title="{{$vo.description}}">{{$vo.description|mb_substr=0,25,'utf-8'}}{{if mb_strlen($vo.description, 'utf-8') > 25}}...{{/if}}</td>
                    <td>{{if $vo.status == 1}}<span class="label label-success">开启</span>{{else}}<span class="label label-danger">关闭</span>{{/if}}</td>
                    <td>
                        <button type="button" class="btn btn-primary btn-xs" onclick="layerOpen('/admin/product_specification?product_model_id={{$vo.id}}', '销售规格')">销售规格</button>
                        <button type="button" class="btn btn-primary btn-xs" onclick="layerOpen('/admin/product_attribute?product_model_id={{$vo.id}}', '产品属性')">产品属性</button>
                        <a type="button" class="btn btn-primary btn-xs" href="{{:url('/admin/product_model/edit')}}?id={{$vo.id}}">编辑</a>
                        <button type="button" class="btn btn-danger btn-xs" onclick="delAction({{$vo.id}})">删除</button>
                    </td>
                </tr>
                {{/volist}}
            </tbody>
        </table>
        <div class="page">
        {{$product_models->appends(Request()->get())->render()|raw}}
        </div>
        {{else}}
        <p class="color-red text-center">数据为空！</p>
        {{/if}}
    </div>
</div>
{{include file="layouts/_foot"}}
<script type="text/javascript">
function delAction(id = '')
{
    if (id == '') {
        var trs = $("tbody :checkbox:checked").parents("tr");
        if (trs.length <= 0) {
            layer.msg('请勾选需删除的数据', {icon: 5, time: 1500});
            return false;
        }
        var ids = '';
        for (var i = 0; i < trs.length; i++) {
            ids += trs[i].id+',';
        }
        id = ids.substr(0, ids.length - 1);
    }
    layer.confirm('确认删除？<br/>删除后将不能使用该模型下的规格、属性。', function(index){
        var load = layer.load();
        $.ajax({
            type: 'GET',
            url: '{{:url("/admin/product_model/delete")}}?id='+id,
            dataType: 'json',
            success: function(res) {
                layer.close(load);
                if (res.code == 401) {
                    goLogin(); return false;
                }
                if (res.code == 400) {
                    layer.msg(res.message); return false;
                }
                if (res.code == 200) {
                    layer.msg('操作成功', {time: 1500}, function() {window.location.reload();});
                    return false;
                }
            },
            error: function(data) {
                console.log(data.msg);
            },
        });     
    });
}    
</script>
</body>
</html>